package com.qhsx.asset.service.impl;

import com.qhsx.asset.domain.AssetEntering;
import com.qhsx.asset.service.AsyncService;
import com.qhsx.common.utils.IdenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author zll
 * @version 1.0
 * @date 2021/10/12 9:00
 */
@Service
@Async
public class AsyncServiceImpl implements AsyncService {

    @Autowired
    IdenUtil idenUtil;




    @Override
    @Async
    public void regIden(String handle, AssetEntering assetEntering){
        String modelName="资产";
        String prefix="86.122.2";

        if(!idenUtil.modelExist(prefix,modelName)){
            List<Map<String,Object>> modelList=new ArrayList<>();
            modelList.add(idenUtil.initModelItem("name","名称"));
            modelList.add(idenUtil.initModelItem("catename","分类名称"));
            modelList.add(idenUtil.initModelItem("number","数量"));
            idenUtil.regModel(prefix,modelName,modelList,3);
        }
        List<Map<String,Object>> idenDataList=new ArrayList<>();
        idenDataList.add(idenUtil.initItem("2000","name",assetEntering.getName()));
        idenDataList.add(idenUtil.initItem("2001","catename",assetEntering.getCate().getTitle()));
        idenDataList.add(idenUtil.initItem("2002","number",assetEntering.getAmount()+""));
        idenUtil.regIden(handle,modelName,idenDataList);
    }
}
